﻿@using KPIS.GERP.Models.ICM
@using KPIS.GERP.Models.ViewModel
@model IEnumerable<PurchaseOrderPenalty>

@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    ViewBag.Title = "กำหนดปรับ";
    ViewBag.Descr = "ข้อมูลกำหนดปรับงานใบสั่ง";

    int? intPoId = ViewBag.PoId;
}
@using (Html.BeginForm("DeleteAll", "Penalty", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    
    <div class="row-fluid">    
         <p id="message"></p>
        <div class="block-button-menu-above">      
              
              @Html.ActionLink("เพิ่ม", "Create", new { PoId = intPoId }
                , new { @class="btn btn-small btn-success button-standard-width", role="button" })
            @Html.ButtonDeleteAll()
        </div>

       <div class="alert-error">@Html.ValidationSummary()</div>

        <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">
					@ViewBag.Title
                </div>
				@Html.Partial("_ExportButton")
            </div>
        </div>

        <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
            <thead>
                <tr>
                    <th class="center" style="width:50px;">
						<!-- Check box delete multiple records column-->
                        <label>
                            <input type="checkbox" />
                            <span class="lbl"></span>
                        </label>
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.CreatedWhen)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Name)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Descr)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.PenaltyRate)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.RateTypeId)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.PurchaseOrder.Code)
                    </th>
                  
					<th class="center" style="width:80px;">
						<!-- Empty head column for export buttons -->&nbsp;
					</th>
                </tr>
            </thead>

            <tbody>
                @foreach (var m in Model ?? new List<PurchaseOrderPenalty>())
                {
                    <tr>
                        <td class="center">
							<!-- Check box all for delete multiple records -->
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.PoPenId)" />
                                <span class="lbl"></span>
                            </label>
                        </td>
                        <td>
							@Html.DisplayFor(model => m.CreatedWhen,"LongDate")
						</td>
						<td>
							@Html.ActionLink(@m.Name, "Details", new { Id = m.PoPenId })
						</td>
                        <td>
							@Html.DisplayFor(model => m.Descr)
						</td>
						<td style="text-align:right">
							@(m.PenaltyRate.HasValue ? Convert.ToString(m.PenaltyRate.Value) : "0")
						</td>
						<td style="text-align:right">
							@Html.DisplayFor(model => m.PenaltyRateType.LookUpName)
						</td>
						<td style="text-align:right">
							@Html.DisplayFor(model => m.PurchaseOrder.Code)
						</td>
                        <td class="td-actions">                           
							    @Html.Partial("_ButtonMenuEachRow", new ExportGrid
                                    {
                                        Id = m.PoPenId,
                                        DetailsUrl = Url.Action("Details") + "/" + m.PoPenId,
                                        EditUrl = Url.Action("Edit") + "/" + m.PoPenId,
                                        DeleteUrl = Url.Action("Delete") + "/" + m.PoPenId
                                    })                           
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}

@section scripts {
    
	<script type="text/javascript">
		$(function () {
			var oTable1 = $('#table').dataTable({
				"aoColumns": [
                    { "bSortable": false },
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    { "bSortable": false }
				]
			});

			$('table th input:checkbox').on('click', function () {
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function () {
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});

			});

			$('[data-rel=tooltip]').tooltip();

			$("form").submit(function () {
				var currentForm = this;
				bootbox.confirm(function (result) {
					var _result = result;
					if (result) {
						$.ajax({
							url: "DeleteAll",
							type: "post",
							dataType: "json",
							data: $(currentForm).serialize(),
							success: function (result) {
								if (result.success) {
								    location.reload();
								    $("#message").html(result.message);
								}
								else {
								    $("#message").html(result.message);
								}
							}
						});
					}
				})
				return false;

			});

		})

	</script>

}